<?php
include('../../config.php');
/**
 * Created by PhpStorm.
 * User: 明哲
 * Date: 2016/4/27
 * Time: 13:50
 */
$startTime =  $_GET['startTime'];
$endTime =  $_GET['endTime'];
$pipeName =  $_GET['pipeName'];
if($startTime !='' && $endTime!=''){
    if($pipeName!=''){
        if($pipeName == 'all'){
            $rows=$mysql->query("select * from `product_data` WHERE `time` BETWEEN '{$startTime}' and '{$endTime}'  order by time DESC");
        }else{
            $rows=$mysql->query("select * from `product_data` WHERE `pipe_name`='{$pipeName}' and `time` BETWEEN '{$startTime}' and '{$endTime}'  order by time DESC");
        }
        $rows = json_encode($rows);
        echo $rows;
    }else{

        $rows=$mysql->query("select * from `product_data` WHERE `time` BETWEEN '{$startTime}' and '{$endTime}'  order by time DESC");
//    $rows = json_decode($rows,true);
        $rows = json_encode($rows);
        echo $rows;
    }

}else{
    $currentTime = date('Y-m-d',time()-60*60*24);
    if($pipeName!=''){
        $rows=$mysql->query("select * from `product_data` WHERE `time`='{$currentTime}' and `pipe_name` = '{$pipeName}'  order by time DESC");
        $rows = json_encode($rows);
        echo $rows;
    }else{
        $rows=$mysql->query("select * from `product_data` WHERE `time`='{$currentTime}'  order by time DESC");
//    $rows = json_decode($rows,true);
        $rows = json_encode($rows);
        echo $rows;
    }
}